import java.util.concurrent.Semaphore;
import java.util.concurrent.locks.ReentrantLock;

public class Test8 {

    public Object locker=new Object();


    public synchronized void Add1(int a,int b){

    }
    public void Add2(int a,int b){
        synchronized (Test8.class){

        }
    }

    public static void main(String[] args) {



    }














    static int num;
    public static void main02(String[] args) throws InterruptedException {
        Semaphore semaphore=new Semaphore(1);
        Thread t1=new Thread(()->{
            for(int i=0;i<50000;i++) {
                try {
                    semaphore.acquire();
                    num++;
                    semaphore.release();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        });
        Thread t2=new Thread(()->{
            for(int i=0;i<50000;i++) {
                try {
                    semaphore.acquire();
                    num++;
                    semaphore.release();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        });

        t1.start();
        t2.start();

        t1.join();
        t2.join();

        System.out.println(num);
    }













    static int count=0;
    public static void main01(String[] args) throws InterruptedException {
        ReentrantLock lock=new ReentrantLock();

        Thread t1=new Thread(()->{
            lock.lock();
            try{
                for(int i=0;i<50000;i++)
                    count++;
            }finally{
                lock.unlock();
            }


        });
        t1.start();

        Thread t2=new Thread(()->{
            lock.lock();
            try{
                for(int i=0;i<50000;i++)
                count++;
            }finally{
                lock.unlock();
            }
        });
        t2.start();

        t1.join();
        t2.join();
        System.out.println(count);
    }
}
